package cn.dansj.handler.interfaces;

import cn.dansj.annotation.MarkAsApi;
import cn.dansj.bean.CurrentThreadLocalUserInfo;
import cn.dansj.bean.LimitReturn;
import cn.dansj.common.utils.json.DictMap;
import cn.dansj.entity.User;
import cn.dansj.handler.InterfaceHandler;
import cn.dansj.utils.project.ProjectUtils;

import java.util.Map;

@SuppressWarnings("all")
@MarkAsApi
public class InterfaceUsage extends InterfaceHandler {

    @Override
    public Object execute(Map<String, Object> paramsMap) {
        final String apiToken = CurrentThreadLocalUserInfo.getCurrentThreadLocalUserInfo().getCacheToken().getApiToken();
        final String todayCount = redisUtils.getString("count@" + apiToken);
        final User user = ProjectUtils.getUserInterfaceTokenInfo(apiToken);
        //根据当前积分计算等级以及限流情况
        LimitReturn limitReturn = ProjectUtils.getLimit(user.getPoint());
        return DictMap.of("todayCount", todayCount, "limit", limitReturn);
    }
}